/**
 * @author Federico Consoli
 *
 * Released under GNU GPLv3 (http://www.gnu.org/licenses/gpl-3.0.txt)
 */



#include "libreria.h"
#include "client_fun.h"

#define cs(x) Connection::char_to_string(x)
#define cus(x) Connection::char_to_uns_short(x)

int main(int argc, const char * argv[]) {
     if ((argc ==2 && argv[1][1]=='h')) {
        cout << "\nSyntax: ./client <nome_client> <Test> <ip_reg> <port_reg> \n";
        cout << "Parameters are preparatory in order of entry, so you can entry no value\n";
        cout << "Or you can entry only ip_reg or only ip_reg+port_reg etc. etc.\n\n";
        cout << "Nome di default 'CLIENT'\n";
        cout << "Test: 0 off (default)\n";
        cout << "Test: 1 on (infinity loop)\n";
        cout << "ip_reg default: 127.0.0.1\n";
        cout << "port_reg default: 40000\n\n";
        return 0;
    }
    int loop = 0;
      
    Fun *client=NULL;
    try {
        
        switch (argc) {
            case 1: 
                client=new Fun;
                break;
            case 2:
                client=new Fun(cs(argv[1]));
                break;
            case 3:
                loop = atoi(argv[2]);
                client=new Fun(cs(argv[1]));
                break;
            case 4:
                loop = atoi(argv[2]);
                client=new Fun(cs(argv[1]),cs(argv[3]));
                break;
            case 5:
                loop = atoi(argv[2]);
                client=new Fun(cs(argv[1]),cs(argv[3]),cus(argv[4]));
                break;    
            
        }
        
        if (client==NULL)
            return 0;
        if (loop)
           // while (1)
                //If you want to do a little test uncomment for cycle and comment while(1)
            for (int i=0 ; i<2; i++)
                client->random_fun();
        else
            client->menu();
    } catch (int num_exc) {
        Exception_class::exc(num_exc);
    }
    delete client;
    return 0;
}



